#include <iostream>

using namespace std;
struct TreeNode
{
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode(int x)
		:val(x)
		,left(nullptr)
		,right(nullptr)
	{}
	TreeNode(int x,TreeNode* l,TreeNode* r)
		:val(x)
		,left(l)
		,right(r)
	{}
};

class Solution 
{
public:
	int maxDepth(TreeNode* root) 
	{
		if (!root)
			return 0;
		int left = maxDepth(root->left);
		int right = maxDepth(root->right);


		return left > right ? left + 1 : right + 1;
	}
};

int main()
{
	TreeNode* D = new TreeNode(5);
	TreeNode* C = new TreeNode(4);
	TreeNode* B = new TreeNode(3, nullptr, D);
	TreeNode* A = new TreeNode(2, C, nullptr);
	TreeNode* root = new TreeNode(1, A, B);

	Solution xz;
	int n = xz.maxDepth(root);
	cout << n << endl;

	return 0;
}